<template>
	<view class="bg_fff">
		<view class="bg-white">
		<view class="cu-bar bg-white">
			<view class="action">
				<text class="cuIcon-title text-orange "></text> 输入问题描述
			</view>
		</view>
		<view class="cu-form-group border margin_top_none">
			<textarea maxlength="-1" v-model="nrtxt"  :disabled="modalName!=null"  placeholder="请输入 : 请详细描述您遇到的问题，例如发病部位等信息，以便专家解答"></textarea>
		</view>
		<view class="cu-list menu" >
			<view class="cu-item" >
				<view class="content">
					<text class="cuIcon-locationfill text-grey"></text>
					<text class="text-grey">{{addmessage}}黑龙江 哈尔滨</text>
				</view>
			</view>
		</view>
		</view>
		<view class="cu-bar bg-white margin-top">
			<view class="cu-bar bg-white">
				<view class="action">
					<text class="cuIcon-title text-orange "></text> 上传图片（最多9张）或视频（不超过15秒）
				</view>
			</view>
		</view>
		<view class="cu-form-group">
			<view class="grid col-4 grid-square flex-sub">
				<view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage" :data-url="imgList[index]">
				 <image :src="imgList[index]" mode="aspectFill"></image>
					<view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
						<text class='cuIcon-close'></text>
					</view>
				</view>
				<view class="solids" @tap="ChooseImage" v-if="imgList.length<9">
					<text class='cuIcon-cameraadd'></text>
				</view>
				<view class="solids" @tap="ChooseVideo" >
					<text class='cuIcon-recordfill'></text>
				</view>
			</view>
		</view>
		<view class="padding">
			<button class="cu-btn block bg-blue margin-tb-sm lg" @click="tj">提交</button>
		</view>
	</view>
</template>

<script>
	import {getwtlr,getimgtest} from '../api/api.js'
	export default {
		data(){
			return{
				nrtxt:'',
				modalName: null,
				addmessage:'',
				imgList: [],
				info:'',
				spinfo:""
			}
		},
		methods:{
			tj(){
				if(this.nrtxt){
					var useIDnameid = uni.getStorageSync('useIDnameid');
					var useIDname = uni.getStorageSync('useIDname');
					let parm={wt_nr:this.nrtxt,wt_dqwz:this.addmessage,wt_tplj:this.info,wt_splj:this.spinfo,djr_bh:useIDnameid,djr_xm:useIDname}
					getwtlr(parm,
					res=>{
						if(res.data.returnData.code=='200'){
							uni.showModal({
							    title: '提示',
							    content: '回答成功',
								showCancel:false
							});
							this.nrtxt='';
						}
					}
					)
				}else{
					uni.showModal({
					    title: '提示',
					    content: '请输入回复内容',
						showCancel:false
					});
				}
				
			},
			ChooseVideo () {
					var self = this;
			      uni.chooseVideo({
			        count: 1,
					maxDuration:15,
			        sourceType: ['camera', 'album'],
			        success: function (sres) {
			          // self.src = res.tempFilePath;
					  uni.showToast({
					      title: sres.duration+'',
					      duration: 2000
					  });
					  
					  if(sres.duration>15){
						  alert('视频长度超过15秒')
					  }
			          uni.showLoading();
					  getimgtest([sres.tempFilePath],res=>{
						  this.spinfo=res.returnData.info
						  uni.hideLoading()
					  })
			    
			        }
			      });
			},
			ChooseImage() {
				uni.chooseImage({
					count: 9, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					/* sourceType: ['album'], //从相册选择 */
					success: (res) => {
						if (this.imgList.length != 0) {
							this.imgList = this.imgList.concat(res.tempFilePaths)
						} else {
							this.imgList = res.tempFilePaths
						}
						let parm=this.imgList
						getimgtest(parm,
						res=>{
							this.info=res.returnData.info
						})
					}
				});
			},
			DelImg(e) {
				this.imgList.splice(e.currentTarget.dataset.index, 1)
			},
			ViewImage(e) {
				uni.previewImage({
					urls: this.imgList,
					current: e.currentTarget.dataset.url
				});
			}
		},
		onLoad(){
	
			console.log(324234)
			let _this=this
		 	uni.getLocation({
			            type: 'wgs84',
			            success: function(res) {
							console.log(8989,res.longitude +''+ res.latitude)
			                //res.longitude, res.latitude;
					
							/* uni.showModal({
							    title: '提示',
							    content: res.longitude +','+ res.latitude,
								showCancel:false
							}); */
			                /* plus.maps.Map.reverseGeocode(
			                    point,
			                    {},
			                    function(event) {
			                        var address = event.address; // 转换后的地理位置
			                        var point = event.coord; // 转换后的坐标信息
			                        var coordType = event.coordType; // 转换后的坐标系类型
			                        console.log(address, 'address');
			                        var reg = /.+?(省|市|自治区|自治州|县|区)/g;           
			                        console.log(address.match(reg));
			                        _this.addressList=address.match(reg).toString().split(",");
			                         _this.address= _this.addressList[1];
									_this.addmessage=(_this.addressList[0]||'')+' '+(_this.addressList[1]||'')+' '+(_this.addressList[2]||'')
			                        
			                    },
			                    function(e) {}
			                ); */
			            }
			        }); 
		}
	}
	
</script>

<style>
	@import "../../colorui/main.css";
	@import "../../colorui/icon.css"; 
	.border{
		border-bottom:2upx solid #eee;
		margin:20upx 0;
	}
	.margin_top_none{
		margin-top: 0;
	}
	
</style>
